<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>权益数据表</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <!-- 导入layui函数库 -->
    <script src="../layui/layui.js" charset="utf-8"></script>
    <!--加载jQuery函数库-->
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
    <style>::-webkit-scrollbar {
        display: none;
    }</style>
</head>
<body>
<blockquote class="layui-elem-quote news_search">
    <!--搜索框-->
    <script type="text/html" id="complain_toolbar">
        <div class="layui-row">
            <form class="layui-form layui-col-md12 x-so" id="Trans_search">
                权益类型：
                <div class="layui-input-inline">
                    <select name="rigType" id="rigType">
                        <option value="">---请选择---</option>
                        <option value="分红">分红</option>
                        <option value="送股">送股</option>
                        <!--<option value="分红送股">分红送股</option>-->
                    </select>
                </div>
                权益除权日：
                <div class="layui-input-inline">
                    <input type="date" id="righDay" name="righDay" placeholder="请输入除权日" 、autocomplete="off"
                           class="layui-input"/>
                </div>
                <button id="search" class="layui-btn layui-btn-primary layui-bg-gray" lay-submit data-type="reload"
                        lay-filter="provinceSearch">
                    <i class="layui-icon">&#xe615;</i>
                </button>
                <b class="layui-btn layui-btn-sm layui-bg-blue" lay-event="lead_in_shang"><i
                        class="layui-icon">&#xe67d;</i>导入交易所数据</b>
                <!--<b class="layui-btn layui-btn-sm layui-bg-blue" lay-event="add"><i class="layui-icon">&#xe67d;</i>导入深交所</b>-->

                <b class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel" style="margin-left:200px "><i
                        class="layui-icon">&#xe640;</i>批量删除</b>

                <b class="layui-btn layui-btn-sm layui-bg-blue" lay-event="add"><i
                        class="layui-icon">&#xe654;</i>添加数据</b>
            </form>
        </div>
    </script>
    <table class="layui-hide" id="EquityTable" lay-filter="EquityList"></table>
</blockquote>
<!--    修改界面-->
<div id="data-main" style="display: none;">
    <div class="layui-row" style="margin-left: 120px;margin-top:25px">
        <form class="layui-form" id="EquityForm" method="POST" lay-skin="line" lay-filter="EquityFormTest">
            <div class="layui-form-item">
                <div class="layui-inline" style="display: none">
                    <label class="layui-form-label layui-icon">权益ID</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rightsId" placeholder="请输入权益ID"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">证券ID</label>
                    <div class="layui-input-inline">
                        <select name="seId" id="seId">
                            <option value="">---请选择权益类型---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">权益登记日</label>
                    <div class="layui-input-inline">
                        <input type="date" name="rigDay" lay-verify="required" placeholder="请输入权益登记日" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">处理状态</label>
                    <div class="layui-input-inline">
                        <select name="proState">
                            <option value="">---未处理---</option>
                            <option value="-1">未处理</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">权益除权日</label>
                    <div class="layui-input-inline">
                        <input type="date" name="righDay" lay-verify="required" placeholder="权益除权日" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="display: none">
                    <label class="layui-form-label layui-icon">到账日期</label>
                    <div class="layui-input-inline">
                        <input type="date" name="dueDate" placeholder="请输入到账日期" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">权益类型</label>
                    <div class="layui-input-inline">
                        <select name="rigType">
                            <option value="">---请选择权益类型---</option>
                            <option value="1">分红</option>
                            <option value="2">送股</option>
                            <!--<option value="3">分红和送股</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">业务日期</label>
                    <div class="layui-input-inline">
                        <input type="date" name="businDate" lay-verify="required" placeholder="请输入业务日期"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label layui-icon">比例</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pro" lay-verify="required" placeholder="按每十股的比例输出" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md4 layui-col-md-offset4">
                <div class="layui-input-block">
                    <button class="layui-btn layui-bg-blue" lay-submit lay-filter="formSave">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
</div>

<!--导入上交所或者深交所弹出框-->
<div id="lead-in" style="display: none;">
    <form method="POST" enctype="multipart/form-data" id="form1" action="/EquityDatas/form">
        <input id="upfile" type="file" class="layui-btn" name="upfile"
               style="background: #06b535;margin-left: 90px;margin-top: 30px;"><br> <br>
        <input type="submit" value="表单提交" class="layui-btn" style="margin-left: 180px;margin-top: 30px;"
               onclick="return checkData()">
        <!-- <input type="button" value="ajax提交" id="btn" name="btn" >-->
    </form>
</div>

<!-- 行中操作按钮 [仅对本行操作]-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/javascript">
    var one;
    layui.use(['table', 'jquery', 'layer', 'util', 'laypage', 'form',], function () {
        var table = layui.table,
            $ = layui.jquery,
            layer = layui.layer,
            util = layui.util,
            laypage = layui.laypage,
            form = layui.form;
        //渲染表格
        var sj = "";
        table.render({
            elem: "#EquityTable",
            url: "../EquityDatas/EquityData",
            toolbar: '#complain_toolbar',
            mehtod: 'get',
            height: 740,
            limit: 15,
            page: true,
            cols: [[
                {checkbox: true},
                {field: "rightsId", title: "权益id", align: "center", sort: true},
                {
                    field: "seId", title: "证券名称", align: "center", templet: function (d) {
                        for (var i = 0; i < one.length; i++) {
                            if (one[i].seId == d.seId) {
                                return one[i].seName;
                            }
                        }
                    }, width: 200
                },
                {field: "rigDay", title: "权益登记日", align: "center"},
                {field: "righDay", title: "权益除权日", align: "center"},
                {field: "dueDate", title: "到账日期", align: "center"},
                {
                    field: "rigType", title: "权益类型", align: "center", templet: function (d) {
                        if (d.rigType == 1) {
                            return "<span style='color: #9BCA63;'>分红</span>";
                        } else if (d.rigType == 2) {
                            return "<span style='color: #FAD860;'>送股</span>";
                        }/*else if(d.rigType==3){
                                return "<span style='color: #60C0DD;'>分红送股</span>";
                            }*/
                    }
                },
                {
                    field: "pro", title: "比例", align: "center", templet: function (d) {
                        if (d.rigType == 1) {
                            return "每10股" + d.pro.toLocaleString() + "元";
                        } else if (d.rigType == 2) {
                            return "每10股" + d.pro.toLocaleString() + "股";
                        }
                    }
                },
                {
                    field: "proState", title: "处理状态", align: "center", templet: function (d) {
                        if (d.proState == 1) {
                            return "<span style='color: #06b535;'>已处理</span>";
                        } else if (d.proState == -1) {
                            return "<span style='color: red;'>未处理</span>";
                        }
                    }
                },
                {field: "businDate", title: "业务日期", align: "center"},
                {fixed: 'right', title: '操作', toolbar: '#barDemo', align: "center"}
            ]],
            limits: [5, 10, 20, 30, 50],

            parseData: function (res) {
                sj = res.da;
                one = res.Securities;
                var oneStr = "<option value=''>--请选择--</option>";
                for (var i = 0; i < one.length; i++) {
                    oneStr += "<option value='" + one[i].seId + "'>" + one[i].seName + "</option>";
                }
                $("#seId").html(oneStr);
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.count,
                    "data": res.data
                }
            }
        });

        //监听添加/修改页的提交操作[该表单的提交操作] [保存按钮]
        //定义页面操作方式
        var mehtod = "";
        form.on('submit(formSave)', function (data) {
            //layer(JSON.stringify(data.field));
            //将表单中各字段值转换为json字符串
            //ajax提交数据
            //使用ajax删除选中的
            //表示分红 有问题
            /* var object={"Id":data.field.rightsId,"businDate":data.field.rigDay,"caId":data.field.rightsId,
                 "businType":data.field.rigType,"capFlow":data.field.rightsId,"money":data.field.rightsId,
                 "fundId":data.field.pro,"states":data.field.rightsId
             };
             if(parseInt(data.field.rigType)==1){




                 var json= JSON.stringify(object);
                 //现金应收应付
               /!*  $.ajax({
                     type:mehtod,
                     url: "/moneycontrollers/moneyities",
                     data: json,
                     dataType:"text",
                     contentType:"application/json;charset=utf-8",//前端发送json字符串到后端，必需设置
                 });*!/
             }else if(parseInt(data.field.rigType)==2){
                 //送股
                 var rightsId=data.field.rightsId;
                 var object={"srapId":rightsId,"businDate":data.field.rigDay,"caId":data.field.seId,
                     "businType":data.field.rightsId,"seId":data.field.seId,"money":data.field.rightsId,
                     "fundId":data.field.pro,"capflow":data.field.rightsId,"states":data.field.rightsId
                 };
                 var json= JSON.stringify(object);
                 //证券应收应付
                 $.ajax({
                     type:mehtod,
                     url: "/securcontroller/securities",
                     data: json,
                     dataType:"text",
                     contentType:"application/json;charset=utf-8",//前端发送json字符串到后端，必需设置
                 });
             }
*/

            //到账日期判断
            var bo = true;
            for (var i = 1; i < 366; i++) {
                var dt = new Date(new Date(Date.parse(data.field.righDay)).getTime() + 60 * 60 * 1000 * 24 * i);
                if (dt.getDay() != 0 && dt.getDay() != 6) {

                    for (var j = 0; j < sj.length; j++) {
                        if (dt.getTime() == new Date(Date.parse(sj[j].holidaydate.substring(0, 10))).getTime()) {
                            data.field.dueDate = sj[j].enddate;
                            bo = false;
                            break;
                        }
                    }
                    if (bo) {
                        data.field.dueDate = dt.getFullYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();
                    }
                    break;
                }
            }

            $.ajax({
                type: mehtod,
                url: "/EquityDatas/EquityData",
                data: JSON.stringify(data.field),
                dataType: "text",
                contentType: "application/json;charset=utf-8",//前端发送json字符串到后端，必需设置
                success: function (msg) {
                    layer.closeAll();//关闭对象框
                    layer.msg(msg);//弹出提示框
                    table.reload("EquityTable");
                }
            });
            return false;
        });
        //表格头部工具栏事件代码，根据lay-event属性值判断执行相应的代码
        table.on('toolbar(EquityList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            //判断事件event值
            switch (obj.event) {
                //批量删除操作：删除选定的多行数据
                case "batchDel":
                    //获得选中的表格行
                    var data = checkStatus.data;
                    //判断是否大于0行
                    if (data.length > 0) {
                        layer.confirm('请确认是否真的删除?', function (index) {
                            //获取所有选择的id
                            var tranIdStr = "";
                            for (var i = 0; i < data.length; i++) {
                                tranIdStr = tranIdStr + data[i].rightsId + ",";//累加字符
                            }
                            //去掉最后多余的逗号
                            tranIdStr = tranIdStr.substring(0, tranIdStr.length - 1);
                            layer.close(index);
                            //证券
                            if (parseInt(data.rigType) == 2) {
                                $.ajax({
                                    type: "put",//提交方式为post
                                    url: "/securcontroller/batchBel/" + tranIdStr,//后台Servlet路径
                                });
                            }
                            //现金
                            if (parseInt(data.rigType) == 1) {
                                $.ajax({
                                    type: "put",//提交方式为post
                                    url: "/moneycontrollers/batchBel/" + tranIdStr,//后台Servlet路径
                                });
                            }
                            //使用ajax删除选中的
                            $.ajax({
                                type: "put",//提交方式为post
                                url: "/EquityDatas/batchBel/" + tranIdStr,//后台Servlet路径
                                success: function (msg) {
                                    layer.msg('删除成功');
                                    //重新加载表格数据
                                    table.reload('EquityTable');
                                }
                            });
                        });
                    } else {
                        //没有选择数据行
                        layer.msg('你至少选一行！');
                    }
                    break;
                case 'add':
                    //显示添加界面
                    mehtod = "post";
                    //清空表单
                    $("#EquityForm")[0].reset();
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: "<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i> 添加新权益数据</span>",
                        area: ['80%', '45%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content: $("#data-main").html(),
                        anim: 1
                    });
                    //将主键设置成允许修改[防止因先修改，后增加时，该字段被设置为只读]
                    $("input[name='rightsId']").prop("readonly", false);
                    break;

                case "lead_in_shang":
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: "<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i> 导入交易数据</span>",
                        area: ['30%', '30%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content: $("#lead-in").html(),
                        anim: 1
                    });

                    //JS校验form表单信息
                function checkData() {
                    var fileDir = $("#upfile").val();
                    var suffix = fileDir.substr(fileDir.lastIndexOf("."));
                    if ("" == fileDir) {
                        alert("选择需要导入的Excel文件！");
                        return false;
                    }
                    if (".xls" != suffix && ".xlsx" != suffix) {
                        alert("选择Excel格式的文件导入！");
                        return false;
                    }
                    return true;
                }

                    break;
            }
        });

        //监听表格行工具(操作)事件 [不能和前面写在一起，原因二者参数有区别：前者toolbar，这里为tool]
        table.on("tool(EquityList)", function (obj) {
            //得到表格行数据
            var data = obj.data;
            //判断事件event值，与lay-event属性比较(使用switch或if梯形结构都可以,前面已经用过switch,
            // 此处使用if梯形结构)
            //判断是否为行修改操作
            if (obj.event == "update") {
                //将设置表单操作方式为修改
                mehtod = "put";
                //设置界面信息
                layer.open({
                    type: 1,
                    title: '修改权益数据',
                    area: ['80%', '45%'],
                    shade: 0.4,
                    skin: 'layui-layer-lan',
                    content: $("#data-main").html(),
                    anim: 1
                });
                //alert(data.empName+","+data.hiredate);
                //将当前行数据显示在表单各字段中
                form.val("EquityFormTest", {
                    "rightsId": data.rightsId,
                    "seId": data.seId,
                    "rigDay": data.rigDay,
                    "righDay": data.righDay,
                    "dueDate": data.dueDate,
                    "rigType": data.rigType,
                    "pro": data.pro,
                    "proState": data.proState,
                    "businDate": data.businDate
                });
                //将主键设置成只读:不允许修改
                $("input[name='rightsId']").prop("readonly", "readonly");
            } else if (obj.event == "delete") {//判断是否为行删除操作
                layer.confirm("真的删除权益数据编为" + data.rightsId + "这行数据吗?", function (index) {
                    //执行表格中删除操作
                    obj.del();
                    layer.close(index);
                    //现金应收应付
                    if (parseInt(data.rigType) == 1) {
                        var moneyId = data.rightsId;
                        $.ajax({
                            type: "delete",
                            url: "/moneycontrollers/moneyities/" + moneyId,
                        });
                    }
                    if (parseInt(data.rigType) == 2) {
                        //证券应收应付
                        $.ajax({
                            type: "post",
                            url: "/securcontroller/EquityDelete",
                            data: "seId=" + data.seId + "&businDate=" + data.businDate,
                        });
                    }
                    $.ajax({
                        type: "delete",
                        url: "/EquityDatas/delete/" + data.rightsId,
                        success: function (msg) {
                            //重新加载表格数据
                            layer.msg(msg);
                            table.reload('EquityTable');
                        }
                    });
                });
            }
        });

        //多条件搜索

        //搜索表单中提交按钮的事件代码
        form.on("submit(provinceSearch)", function (data) {
            //定义表单数据对象
            var formData = data.field;
            //得到表单数据json字符串
            var json = JSON.stringify(data.field);
            //alert(json);
            //重新加载表格对象
            table.reload("EquityTable", {
                //页码
                page: {
                    curr: 1
                },
                //条件数据，会带到后台
                where: {
                    rigType: formData.rigType,
                    righDay: formData.righDay
                }
            });
            return false;
        });
    });
</script>
</blockquote>
</body>
</html>